/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-11-29 09:29:09
 * @LastEditors: 商晓彬
 * @LastEditTime: 2021-12-31 09:42:17
 */
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
import { LazyLoadEvent } from 'primeng/api';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { ProductionReviewServiceProxy,CommonServiceProxy ,ProductTaskBoardServiceProxy,TaskReportTitleDto} from '@shared/service-proxies/service-proxies';
import * as moment from 'moment';


@Component({
    selector: 'app-production-task',
    templateUrl: './production-task.component.html',
    styleUrls: ['./production-task.component.less']
})
export class ProductionTaskComponent extends AppComponentBase {

    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _productionReviewServiceProxy: ProductionReviewServiceProxy,
        private _commonServiceProxy: CommonServiceProxy,
        private _productTaskBoardServiceProxy: ProductTaskBoardServiceProxy,
    ) {
        super(injector);
    }
    date: any;
    week: any;
    time: any;
    timer: any;
    fullScreen = false;
    model = undefined;
    modelOptions = [
        {
            label: '请选择型号',
            value: undefined
        }
    ];
    sendTime = undefined;
    sendTimeOptions = [
        {
            label: '请选择发次',
            value: undefined
        }
    ];
    rangeDates = undefined;//日期
    unit = undefined;
    unitOptions = [
        {
            label: '请选择班组',
            value: undefined
        }
    ];
    stuts = new TaskReportTitleDto;
    tableData = [];
    type = undefined;
    getIntervalData() {
        //型号
        this._commonServiceProxy.getModelList(
            )
                .pipe(finalize(() => { })).subscribe(result => {
                    for (const item of result) {
                        let data = { label: undefined, value: undefined };
                        data.label = item.label;
                        data.value = item.value;
                        this.modelOptions.push(data);
                    }
                })
            //班组
            this._productTaskBoardServiceProxy.getOrganizationUnitForBoard(
                )
                    .pipe(finalize(() => { })).subscribe(result => {
                        for (const item of result) {
                            let data = { label: undefined, value: undefined };
                            data.label = item.label;
                            data.value = item.value;
                            this.unitOptions.push(data);
                        }
                    })
            //数量
            this._productTaskBoardServiceProxy.getTaskReportTitle(
                undefined,
                undefined,
                undefined,
                undefined,
                undefined,
                )
                .pipe(finalize(() => { })).subscribe(result => {
                    this.stuts = result;
                })
            //表格
            this._productTaskBoardServiceProxy.getTaskReportList(
                undefined,
                undefined,
                undefined,
                undefined,
                undefined,
                undefined
                )
                .pipe(finalize(() => { })).subscribe(result => {
                    this.tableData = result.items;
                })
    }
    ngOnInit() {
        this.getIntervalData();
        setInterval(() => {
            this.search();
        }, 3600000);
    }
    search() {
        let startTime = undefined;
        let endTime = undefined;
        if (this.rangeDates != undefined) {
            startTime = this.rangeDates[0];
            endTime = this.rangeDates[1];
        }
         //数量
        this._productTaskBoardServiceProxy.getTaskReportTitle(
            this.model,
            this.sendTime,
            startTime,
            endTime,
            this.unit
            )
            .pipe(finalize(() => { })).subscribe(result => {
                this.stuts = result;
            })
        //表格数据
        this._productTaskBoardServiceProxy.getTaskReportList(
            this.model,
            this.sendTime,
            startTime,
            endTime,
            this.unit,
            this.type
            )
            .pipe(finalize(() => { })).subscribe(result => {
                this.tableData = result.items;
            })
    }
    getTypeTable(type) {
        this.type = type;
        let startTime = undefined;
        let endTime = undefined;
        if (this.rangeDates != undefined) {
            startTime = this.rangeDates[0];
            endTime = this.rangeDates[1];
        }
         //表格数据
         this._productTaskBoardServiceProxy.getTaskReportList(
            this.model,
            this.sendTime,
            startTime,
            endTime,
            this.unit,
            type
            )
            .pipe(finalize(() => { })).subscribe(result => {
                this.tableData = result.items;
            })
    }
    onchange(event) {
        this.sendTimeOptions = [
            {
                label: '请选择发次',
                value: undefined
            }
        ];
        //发次
        this._commonServiceProxy.getLotNoList(
            this.model
        )
            .pipe(finalize(() => { })).subscribe(result => {
                for (const item of result) {
                    let data = { label: undefined, value: undefined };
                    data.label = item.label;
                    data.value = item.value;
                    this.sendTimeOptions.push(data);
                }
            })
    }
    full() {
        if (!this.fullScreen) {
            this.search();
            const docElmWithBrowsersFullScreenFunctions = document.getElementById('main') as HTMLElement & {
                webkitRequestFullscreen(): Promise<void>;
            };
            if (docElmWithBrowsersFullScreenFunctions.requestFullscreen) {
                docElmWithBrowsersFullScreenFunctions.requestFullscreen();
            } else if (docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
                docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen();
            }
            this.fullScreen = true;
        } else {
            this.search();
            const docWithBrowsersExitFunctions = document as Document & {
                webkitExitFullscreen(): Promise<void>;
            };
            if (docWithBrowsersExitFunctions.exitFullscreen) {
                docWithBrowsersExitFunctions.exitFullscreen();
            } else if (docWithBrowsersExitFunctions.webkitExitFullscreen) { /* Chrome, Safari and Opera */
                docWithBrowsersExitFunctions.webkitExitFullscreen();
            }
            this.fullScreen = false;
        }
    }
    ngAfterContentChecked() {
        //渲染完成后
        this.getNowDate();
        if (this.timer) {
        } else {
            this.timer = setInterval(this.getNowDate, 1000);
        }
    }
    getNowDate() {
        let nowDate = new Date();
        this.date = moment(nowDate).format('YYYY-MM-DD');
        var a = ["日", "一", "二", "三", "四", "五", "六"];
        var week = new Date().getDay();
        this.week = "星期" + a[week];
        this.time = moment(nowDate).format('HH:mm:ss');
    }

}
